package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QMenu1;
import com.ruoyi.system.service.IQMenu1Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 顶层菜单Controller
 * 
 * @author ruoyi
 * @date 2024-06-14
 */
@Controller
@RequestMapping("/system/menu1")
public class QMenu1Controller extends BaseController
{
    private String prefix = "system/menu1";

    @Autowired
    private IQMenu1Service qMenu1Service;

    @RequiresPermissions("system:menu1:view")
    @GetMapping()
    public String menu1()
    {
        return prefix + "/menu1";
    }

    /**
     * 查询顶层菜单列表
     */
    @CrossOrigin
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QMenu1 qMenu1)
    {
        startPage();
        List<QMenu1> list = qMenu1Service.selectQMenu1List(qMenu1);
        return getDataTable(list ,  1);
    }

    /**
     * 导出顶层菜单列表
     */
    @CrossOrigin
    @RequiresPermissions("system:menu1:export")
    @Log(title = "顶层菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QMenu1 qMenu1)
    {
        List<QMenu1> list = qMenu1Service.selectQMenu1List(qMenu1);
        ExcelUtil<QMenu1> util = new ExcelUtil<QMenu1>(QMenu1.class);
        return util.exportExcel(list, "顶层菜单数据");
    }

    /**
     * 新增顶层菜单
     */
    @CrossOrigin
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存顶层菜单
     */
    @RequiresPermissions("system:menu1:add")
    @Log(title = "顶层菜单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QMenu1 qMenu1)
    {
        return toAjax(qMenu1Service.insertQMenu1(qMenu1));
    }

    /**
     * 修改顶层菜单
     */
    @CrossOrigin
    @RequiresPermissions("system:menu1:edit")
    @GetMapping("/edit/{qId}")
    public String edit(@PathVariable("qId") Long qId, ModelMap mmap)
    {
        QMenu1 qMenu1 = qMenu1Service.selectQMenu1ByQId(qId);
        mmap.put("qMenu1", qMenu1);
        return prefix + "/edit";
    }

    /**
     * 修改保存顶层菜单
     */
    @CrossOrigin
    @RequiresPermissions("system:menu1:edit")
    @Log(title = "顶层菜单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QMenu1 qMenu1)
    {
        return toAjax(qMenu1Service.updateQMenu1(qMenu1));
    }

    /**
     * 删除顶层菜单
     */
    @CrossOrigin
    @RequiresPermissions("system:menu1:remove")
    @Log(title = "顶层菜单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qMenu1Service.deleteQMenu1ByQIds(ids));
    }
}
